var app = getApp(), api = require("../../api.js"), images = require('../../utils/images.js');

Page({
    data: {
      successIcon: images.nearbyShop.successIcon,
      failIcon: images.nearbyShop.failIcon,
    },
    onLoad: function(t) {
      var that = this;
      if(t.status == 0){
        that.setData({
          img: !0,
          resultMsg: '提交成功',
          resultTip: '正在等待审核，请尽快缴费',
          pay: !0
        });
      } else if (t.status == 1) {
        app.request({
          url: api.mch.applys,
          success: function (d) {
            console.log(d);
            if (d.code == 0) {
              var msg = '';
              if (d.data.apply.mch_common_cat_id == 1) {
                msg = '本地自营';
              } else if (d.data.apply.mch_common_cat_id == 2) {
                msg = '本地商家';
              } else if (d.data.apply.mch_common_cat_id == 3) {
                msg = '特产美食';
              }
              that.setData({
                img: !0,
                resultMsg: '审核通过',
                resultTip: '恭喜您，入驻' + msg + '成功'
              });
            }else{
              wx.showToast({
                title: d.msg,
                image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
              });
            }
          },
          fail: function (d) {
            wx.showToast({
              title: '查询状态失败',
              image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
            });
          }
        });
      } else if (t.status == 2) {
        app.request({
          url: api.mch.applys,
          success: function (d) {
            console.log(d);
            if (d.code == 0) {
              that.setData({
                img: !1,
                resultMsg: '审核未通过',
                resultTip: d.data.apply.review_result,
                fail: !0
              });
            } else {
              wx.showToast({
                title: d.msg,
                image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
              });
            }
          },
          fail: function (d) {
            wx.showToast({
              title: '查询状态失败',
              image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
            });
          }
        });
      } else if (t.status == 3) {
        app.request({
          url: api.mch.applys,
          success: function (d) {
            console.log(d);
            if (d.code == 0) {
              if(d.data.apply.is_show == 0){
                that.setData({
                  img: !0,
                  resultMsg: '等待审核',
                  resultTip: '正在等待审核，请尽快缴费',
                  pay: !0
                });
              }else{
                that.setData({
                  img: !0,
                  resultMsg: '正在审核',
                  resultTip: '正在审核中，请耐心等待'
                });
              }
            } else {
              wx.showToast({
                title: d.msg,
                image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
              });
            }
          },
          fail: function (d) {
            wx.showToast({
              title: '查询状态失败',
              image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
            });
          }
        });
      }
    },
    payment: function(e){
      wx.showLoading({
        title: '加载中',
      }),app.request({
        url: api.mch.apply_pay,
        success: function (d) {
          console.log(d);
          if (d.code == 0) {
            wx.requestPayment({
              'timeStamp': d.data.timeStamp,
              'nonceStr': d.data.nonceStr,
              'package': d.data.package,
              'signType': 'MD5',
              'paySign': d.data.paySign,
              'success': function (res) {
                console.log(res);
                wx.redirectTo({
                  url: '/pages/admission-result/admission-result?status=3'
                });
              },
              'fail': function (res) {
                wx.showToast({
                  title: '支付失败',
                  image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
                });
              }
            })
          } else {
            wx.showToast({
              title: d.msg,
              image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
            });
          }
        },
        fail: function (d) {
          wx.showToast({
            title: '支付失败',
            image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
          });
        },
        complete: function (d) {
          wx.hideLoading();
        }
      });
    },
    resubmit: function(e){
       wx.redirectTo({
         url: '/pages/admission/admission'
       });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});